﻿Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.Activities
    <ActivityDesignerTheme(GetType(WebServiceDesignerTheme))> _
    Friend NotInheritable Class WebServiceReceiveDesigner
        Inherits ActivityDesigner
        ' Methods
        Protected Overrides Sub OnActivityChanged(ByVal e As ActivityChangedEventArgs)
            MyBase.OnActivityChanged(e)
            If (Not e.Member Is Nothing) Then
                If (e.Member.Name = "InterfaceType") Then
                    If (Not MyBase.Activity.Site Is Nothing) Then
                        Dim newValue As Type = [TryCast](e.NewValue,Type)
                        If (Not newValue Is Nothing) Then
                            New InterfaceTypeFilterProvider(MyBase.Activity.Site).CanFilterType(newValue, True)
                        End If
                        Dim activity1 As Activity = e.Activity
                        Dim descriptor As PropertyDescriptor = TypeDescriptor.GetProperties(MyBase.Activity).Item("MethodName")
                        If (Not descriptor Is Nothing) Then
                            descriptor.SetValue(MyBase.Activity, String.Empty)
                        End If
                    End If
                ElseIf (e.Member.Name = "MethodName") Then
                    [TryCast](e.Activity,WebServiceInputActivity).ParameterBindings.Clear
                End If
                If ((e.Member.Name = "InterfaceType") OrElse (e.Member.Name = "MethodName")) Then
                    TypeDescriptor.Refresh(e.Activity)
                End If
                Dim activity As Activity
                For Each activity In WebServiceActivityHelpers.GetSucceedingActivities(MyBase.Activity)
                    If (TypeOf activity Is WebServiceOutputActivity AndAlso (DirectCast(activity, WebServiceOutputActivity).InputActivityName = MyBase.Activity.QualifiedName)) Then
                        TypeDescriptor.Refresh(activity)
                    End If
                Next
            End If
        End Sub

        Protected Overrides Sub PreFilterProperties(ByVal properties As IDictionary)
            MyBase.PreFilterProperties(properties)
            [TryCast](MyBase.Activity,WebServiceInputActivity).GetParameterPropertyDescriptors(properties)
            If properties.Contains("InterfaceType") Then
                properties.Item("InterfaceType") = New WebServiceInterfacePropertyDescriptor(MyBase.Activity.Site, [TryCast](properties.Item("InterfaceType"),PropertyDescriptor))
            End If
        End Sub

    End Class
End Namespace

